<template>
    <div class="seach">
      <div class="seach_body">
        <!-- 开始 -->
        <el-table :data="this.users_Info" border stripe><!-- 带边框、斑马纹 -->
          <!-- <el-table-column type="index"></el-table-column> -->
          <el-table-column label="订阅编号" prop="id"></el-table-column>
          <el-table-column label="订阅图书编号" prop="bookId"></el-table-column>
          <el-table-column label="订阅读者编号" prop="userId"></el-table-column>
          <el-table-column label="订阅书名" prop="bookName"></el-table-column>
          <el-table-column label="订阅时间" prop="subtime"></el-table-column>
          <!-- <el-table-column label="身份" prop="ismaind"></el-table-column>  -->

          <el-table-column label="操作" width="200px">
              <template slot-scope="scope">
                <!-- <el-tooltip effect="dark" content="修改" placement="top">
                    <el-button type="primary" icon="el-icon-edit" size="mini"  @click="updata_data(scope.row)"></el-button>
                  </el-tooltip> -->
                  <el-tooltip effect="dark" content="删除" placement="top">
                    <el-button type="danger" icon="el-icon-delete" @click="updata_delete(scope.row)" size="mini"></el-button>
                  </el-tooltip>
              </template>
          </el-table-column>
        <!-- </div> -->
        </el-table>
        <!-- 结束 -->
        <Delete v-if="this.delete" :todelete="this.todelete"></Delete>
      </div>
      <div class="seach_bottom">
        <div class="bottom_buttons">
          <el-pagination
           background
           layout="prev, pager, next"
            @current-change="handleSizeChange"   
           @prev-click="handleCurrentChange"
           @next-click="handleCurrentChange"
           :total=this.total>
          </el-pagination>
        </div>
      </div>
    </div>
  </template>
  <script>
  import Delete from '../components/Delete.vue'
  export default({
    data(){
        return{
          key:0,
            total:0,
            delete:false, 
            id:"", 
            users_Info:[
            ],
            tonote:{},
            test:[{id:"20100140205",bookId:"123455",userId:"kuangfeng",bookName:"男",subtime:"123456@qq.com",},
          ]
        }
    },
    components:{

      Delete,
    },
    methods:{
      async getsubList() {
        this.axios.get('http://192.168.43.171:8081/subscription/select', {
                        params:{
                         key:this.key,        // 参数 id
                        }
                     // 参数 name
                  }).then( (response)=> {
                    console.log(response.data);
                    console.log(response);
                    // this.total = res.data.total;
                    this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                    
                   
                    // console.log(this.users_Info);
                  }).catch(function (error) {
                    console.log(error);
                  });
      },
      // 当前页
      handleSizeChange(val) {
        this.key=val
        this.axios.get('http://192.168.43.171:8081/subscription/select', {
                        params:{
                          key:this.key,
                        //  psWord: this.password,
                        }
                     // 参数 name
                  }).then( (response)=> {
                    console.log(response.data);
                    console.log(response);
                    // this.getsubList();
                    this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                    console.log("1234");
                    console.log(this.users_Info);
                  }).catch(function (error) {
                    console.log(error);
                  });
        console.log(`当前 ${val} 页`);
      },
      // 下一页或者上一页
      handleCurrentChange(val) {
        this.key=val
        this.axios.get('http://192.168.43.171:8081/subscription/select', {
                        params:{
                          key:this.key,
                        // id:this.id ,        // 参数 id
                        //  psWord: this.password,
                        }
                     // 参数 name
                  }).then( (response)=> {
                    // this.getsubList();
                    this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                  }).catch(function (error) {
                    console.log(error);
                  });
        console.log(`去第 ${val}页`);
      },

      // 删除记录
      updata_delete(row){
        this.delete=true;
        console.log(row);
        this.id=row.id
        
      },
      // 删除图书后被调用的delete调用函数
      todelete(){
        console.log("订阅信息删除被调用了");
        // 
        this.axios.get('http://192.168.43.171:8081/subscription/delete', {
                        params:{
                        id:this.id ,        // 参数 id
                        //  psWord: this.password,
                        }
                     // 参数 name
                  }).then( (response)=> {
                    console.log(response);
                    this.getsubList();
                    this.$message({
                    message: '删除成功',
                   type: 'success'
                   });
                  }).catch(function (error) {
                    console.log(error);
                  });
                  // 
      }
    },
    mounted(){
          // 删除全局事件总线
          this.$bus.$on ('bus_delete_cancel', (data) => {
            this.delete=data;
            // console.log(data);
            if(data==1){
              this.delete=false
            }
          }),
          this.$bus.$on ('bus_delete', (data) => {
            // this.delete=data;
            console.log(data);
            if(data==1){
              this.delete=false
            }
          })
          this.getsubList()
      },
      beforeDestroy(){
          // this.$bus.$off('bus_delete_cancel')
          this.$bus.$off('bus_delete')
        },
        beforeRouteEnter:(to,from,next)=>{
   const ismaind=sessionStorage.getItem("ismaind")
   console.log(ismaind);
    if (ismaind==1) {
      next()
    } else {
      alert("无权限")
    }
  }
  })
  </script>
  <style lang="less" scoped>
  .seach{
    width: 100%;
    height: 100%;
    position: absolute;
    .seach_seach{
      position: absolute;
      right: 50px;
      height: 6%;
      width: 30%;
      // background-color: #67c58b;
      .seach_input{
         position: absolute;
         width: 70%;
         top: 4px;
      }
      .input_buttons{
       position: absolute;
       top: 16%;
       right: 11%;
      }
    }
    .seach_body{
    // background-color: aquamarine;
    // background-color: rgb(245, 243, 243);
    background-color: #fff;
    position: absolute;
    top: 7%;
    height: 80%;
    width: 100%;
    td{
      // background-color: rgb(245, 243, 243);
      // background-color: rgba(247, 248, 243,0.95);
      background-color: #fff;
      th{
        // background-color: rgb(245, 243, 243);
      }
  
    }
    }
  
    .seach_bottom{
      // background-color: #5f9ca1;
      height: 10%;
      width: 100%;
      bottom: 1%;
      position: absolute;
      .bottom_buttons{
        position: absolute;
        top: 32%;
        height: 40%;
        width: 20%;
        left: 25%;
        // transform: translate(-50%,-50%);
        // background-color: bisque;
      }
  
    }
  }
 
  </style>